package change.reference.to.value;

/**
 * Created by Administrator on 2018/1/25.
 * 货币种类   它是一个引用对象
 * 把它变成一个值对象(检查它是否不可变)
 */
public class Currency {

    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Currency(String code) {
        this.code = code;
    }

    public boolean equals(Object arg) {
        if (!(arg instanceof Currency)) {
            return false;
        }
        Currency other = (Currency) arg;
        return (code.equals(other.code));
    }

    public int hashCode() {
        return code.hashCode();
    }

    public static void main(String[] args) {
        System.out.println(new Currency("USD").equals(new Currency("USD")));
    }
}
